package org.ruanjj.mypow;

public class Solution {
    public double myPow(double x, int n) {
        return n >= 0 ? mulMyPow(x,n):1/mulMyPow(x,-n);
    }

    private double mulMyPow(double x, int n){
        if(n == 0){
            return 1.0;
        }
        double y = mulMyPow(x,n/2);
        return n % 2==0 ? y*y:x*y*y;
    }
}
